/*
	This file is part of SRServerLibrary.
	SRServerLibrary is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.
	
	SRServerLibrary is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.
	
	You should have received a copy of the GNU General Public License
	along with SRServerLibrary.  If not, see <http://www.gnu.org/licenses/>.
*/


#ifndef SRNETWORKSERVER_H
#define SRNETWORKSERVER_H

#include <QtNetwork>
#include "SRSettings.h"
#include "SRCommand.h"
#include <QList>
#include <QTcpServer>
#include <QTcpSocket>
#include "SRMessenger.h"


class SRNetworkServer : public QObject
{
Q_OBJECT

public:
	SRNetworkServer(SRSettings *s, SRMessenger *m);
	
private:
	void startListening();
	void stopListening();
	void sendMessage(SRCommand);
	void broadcast(SRCommand);

	SRSettings *settings;
	SRMessenger *messenger;
	QTcpServer server;
	QList<QTcpSocket*> connections;

private slots:
	void clientConnected();
	void receiveMessage();
};

#endif
